import { ref, reactive, onMounted, nextTick } from 'vue'
import { taskAddApi, taskDeleteApi, hazardPageApi } from '@/api/ReviewBusiness/01Project/project'
import useInstance from '@/hooks/useInstance';
import { EditType } from '@/type/BaseEnum'
export default function abnormalModel() {
  // 全部坐在一个里面
  const rules = reactive({
    hazardLevel: [
      { required: true, message: '请选择异常登记', trigger: 'blur' }
    ],
    causeAnalysis: [
      { required: true, message: '请填写原因分析', trigger: 'blur' }
    ],
    description: [
      { required: true, message: '请填写问题描述', trigger: 'blur' }
    ],
    treatment: [
      { required: true, message: '请填写处理说明', trigger: 'blur' }
    ],
  })
  const ProjectData = reactive({
    Loading: false,
    height: 100,
    list: [] as any,
    search: {
      page: 1,
      size: 200
    }
  })
  let dialogModel = reactive({
    auditorStageId: "",
    auditorItageId: '0',//审核阶段
    causeAnalysis: '', //	原因分析 
    description: '', //	描述
    hazardLevel: '', //	异常等级
    treatment: '', //	处理说明
    hazardCites: [] as any, // 引用其他文件 文件id 怎么搞 设计是直接调用多少页嘛 然后 展示矩形
    recordId: '', // 批注id
    status: '0',//0:待激活，1：待处理，2：已完成，3：已终止
    updateId: '' //处理人Id
  })
  const RefAbnormal = ref<{ show: (type: string, row?: any) => void }>()
  const addAbnormalBtn = () => {
    RefAbnormal?.value?.show(EditType.ADD)
  }
  const clearData = () => {
    dialogModel.auditorItageId = '0'
    dialogModel.auditorStageId = ""
    dialogModel.causeAnalysis = ''
    dialogModel.description = ''
    dialogModel.hazardLevel = ''
    dialogModel.treatment = ''
    dialogModel.recordId = ''
    dialogModel.status = '0'
    dialogModel.updateId = ''
    dialogModel.hazardCites = [
      {
        distance: [
          {
            distLeft: "",
            distTop: "",
            height: "",
            id: "",
            page: 0,
            rectIndex: "",
            size: 0,
            sort: "",
            width: ""
          }
        ],
        imageId: "",
        page: 0,
        size: 0,
        sort: ""
      }
    ]

  }
  onMounted(() => {
    getAbnormalList()
    nextTick(() => {
      ProjectData.height = window.innerHeight - 320
    })
  })
  const getAbnormalList = async () => {
    console.log(11111111111);
    ProjectData.Loading = true
    const res = await hazardPageApi(ProjectData.search)
    if (res.code === 200) {
      ProjectData.Loading = false
      ProjectData.list = res.data.records
    }
  }
  const tableRowClassName = ({ row, rowIndex }) => {
    if (rowIndex % 2 === 1) {
      return "warning-row";
    } else {
      return "success-row";
    }
  }

  return {
    rules, dialogModel, addAbnormalBtn, RefAbnormal, ProjectData, getAbnormalList, clearData, tableRowClassName
  }
}